/*
 * @Author: 0x9DEFA478
 * @Date: 2022-02-14 22:08:03
 * @LastEditTime: 2022-08-20 18:18:34
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * QQ:2652450237
 * ============================================================================================================================================
 * 
 * 
 * 
 *                                                                                               ************      ****************************
 *                                                                                             ************      ****************************  
 *                                                                                           ************      ****************************    
 *                                                                                         ************      ****************************      
 *                                                                                       ************      ************                        
 *                                                                                     ************      ************                          
 *                                                                                   ************      ************                            
 *                                                                                 ************      ************                              
 *                                                                               ************      ************                                
 *                                                                             ************      ************                                  
 *                                                                           ************      ************                                    
 *                                                                         ************      ************                                      
 *                                                                       ************      ************                                        
 *                                                                     ************      ************                                          
 *                                                                   ************      ************                                            
 *                                                                 ************      ************                                              
 *                                                               ************      ************                                                
 *                                                             ************      ************                                                  
 *                                                           ************      ************                                                    
 *                                                         ************      ************                                                      
 *                                                       ************      ************                                                        
 *                                                     ************      ************                                                          
 *                                                   ************      ************                                                            
 *                                                 ************      ************                                                              
 *                                               ************      ************                                                                
 *                                             ************      ************                                                                  
 *                                           ************      ************                                                                    
 *                                         ************      ************                                                                      
 *                                       ************      ************                                                                        
 *                                     ************      ************                                                                          
 *                                   ************      ************                                                                            
 *                                 ************      ************                                                                              
 *                               ************      ************                                                                                
 *                             ************      ************                                                                                  
 *                           ************      ************                                                                                    
 *                         ************      ************                                                                                      
 *       ****************************      ************                                                                                        
 *     ****************************      ************                                                                                          
 *   ****************************      ************                                                                                            
 * ****************************      ************                                                                                              
 * 
 * 
 * 
 * ============================================================================================================================================
 * 
 */
#include "../H_NES_Mapper.h"




#define ThisMapper Cartridge.Mapper.SpecificMapper.Mapper4




void H_NES_Mapper74_CHR_Write(Hbyte Value,Huint16 Address,void* v){
  H_NES_Console* Console;
  Hbyte* BankAddress;
  Husize Offset;

  Console=v;

  BankAddress=Console->ThisMapper.CHR_Banks.Base0000_1KB[(Address>>10)&0x0007U];

  Offset=(Husize)((Hbyte*)BankAddress-(Hbyte*)Console->Cartridge.Mapper.CHR_ROM);
  Offset>>=10;
  if((Offset>7)&&(Offset<10)){
    Console->ThisMapper.Variant.Mapper74.CHR_RAM[(Offset-8)*0x400+(Address&0x03FFU)]=Value;
  }else{
    if(Console->Cartridge.Mapper.CHR_RAM!=NULL){
      BankAddress[Address&0x03FFU]=Value;
    }
  }
}
Hbyte H_NES_Mapper74_CHR_Read(Huint16 Address,void* v){
  H_NES_Console* Console;
  Hbyte* BankAddress;
  Husize Offset;

  Console=v;

  BankAddress=Console->ThisMapper.CHR_Banks.Base0000_1KB[(Address>>10)&0x0007U];

  Offset=(Husize)((Hbyte*)BankAddress-(Hbyte*)Console->Cartridge.Mapper.CHR_ROM);
  Offset>>=10;
  if((Offset>7)&&(Offset<10)){
    return Console->ThisMapper.Variant.Mapper74.CHR_RAM[(Offset-8)*0x400+(Address&0x03FFU)];
  }else{
    return BankAddress[Address&0x03FFU];
  }
}




#undef ThisMapper



